JavaScript

$u.s.pad

Syntax

$u.s.pad(str as string, padLength as number, padString as string [, position as string])

Arguments

strstring

The string to pad.

padLengthnumber

The size of the padding.

padStringstring

The character to used to pad the string.

positionstring

(Optional) Defines where padding should be applied - left, right, or both sides. This property can be one of the following values:

Description

Pad a string with a passed in padding string. Optionally choose where the padding should be positioned.

Example

var str = 'hello';
str = $u.s.pad(str,11,'*');
/* result is: '******hello'*/

str = 'hello';
str = $u.s.pad(str,11,'*','r');
/* result is: 'hello******'*/

str = 'hello';
str = $u.s.pad(str,11,'*','c');
/* result is: '***hello***'*/